using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace BatchFileList
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void ButtonGetFileList_Click(object sender, EventArgs e)
		{
			ListStrings.Items.Clear();
			DirectoryInfo dir = new DirectoryInfo(TextPath.Text);
			foreach (FileInfo file in dir.GetFiles())
			{
				ListStrings.Items.Add(file.Name);
			}
		}

		private void GenerateButton_Click(object sender, EventArgs e)
		{
			string pattern = TextPattern.Text;
			StringBuilder output = new StringBuilder();

			foreach (object item in ListStrings.Items)
			{
				string result = string.Format(pattern, item);
				output.AppendLine(result);
			}

			TextOutput.Text = output.ToString();
		}

		private string ValidPath
		{
			get
			{
				if (!string.IsNullOrEmpty(TextPath.Text)
					&& Directory.Exists(TextPath.Text))
				{
					return TextPath.Text;
				}
				return "";
			}
		}

		private void ButtonBrowse_Click(object sender, EventArgs e)
		{
			FolderBrowserDialog d = new FolderBrowserDialog();
			string path = ValidPath;
			if (!string.IsNullOrEmpty(path))
			{
				d.SelectedPath = path;
			}
			DialogResult result = d.ShowDialog();
			if (result == DialogResult.OK)
			{
				TextPath.Text = d.SelectedPath;
			}
		}
	}
}